package com.yc.bdw.Activity;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;

import com.yc.bdw.Adapter.ProductsGridViewAdapter;
import com.yc.bdw.R;
import com.yc.bdw.model.Product;
import com.yc.bdw.Widget.MyGridView;

import org.kymjs.kjframe.KJActivity;
import org.kymjs.kjframe.ui.BindView;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class AffairActivity extends KJActivity {
    @BindView(id = R.id.affair_back, click = true)
    private ImageView backBtn;
    @BindView(id = R.id.affair_adver1, click = true)
    private ImageView adver1Img;
    @BindView(id = R.id.affair_adver2, click = true)
    private ImageView adver2Img;
    @BindView(id = R.id.affair_commodities, click = true)
    private MyGridView commoditiesGridView;

    private List<Product> products = new ArrayList<Product>();
    private ProductsGridViewAdapter adapter;

    @Override
    public void setRootView() {
        setContentView(R.layout.activity_affair);
    }

    @Override
    public void initData() {
        super.initData();

        init();

        adapter = new ProductsGridViewAdapter(aty);
        adapter.setList(products);
    }

    private void init() {
        Product item = new Product();
        item.setPrice(BigDecimal.valueOf(11));
        item.setNumber(6);
        item.setName("酒");
        products.add(item);

        Product item2 = new Product();
        item2.setPrice(BigDecimal.valueOf(22));
        item2.setNumber(7);
        item2.setName("酒2");
        products.add(item2);

        Product item3 = new Product();
        item3.setPrice(BigDecimal.valueOf(33));
        item3.setName("酒3");
        item3.setNumber(8);
        products.add(item3);

        Product item4 = new Product();
        item4.setPrice(BigDecimal.valueOf(44));
        item4.setName("酒4");
        item4.setNumber(9);
        products.add(item4);
    }

    @Override
    public void initWidget() {
        super.initWidget();

        commoditiesGridView = (MyGridView) findViewById(R.id.affair_commodities);
        commoditiesGridView.setAdapter(adapter);
        commoditiesGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                showActivity(aty, DetailActivity.class);
            }
        });
    }

    @Override
    public void widgetClick(View v) {
        super.widgetClick(v);
        switch (v.getId()) {
            case R.id.affair_back:
                finish();
                break;
        }
    }
}
